|
|
|
|
|
|
|
Creating the Heart of the Program |
|
|
|
|
|
|
|
|
The forms provide the interface of the program, but the real heart of the program is a group of procedures that actually display the data and set the program up. To create the procedures, you first need to add a module to your program. You can do this by choosing Project, Add, or by selecting Module from the Add Object button's drop-down menu. |
|
|
|
|
|
|
|
|
See "Determining the Scope of Procedures and Functions," p. 232 |
|
|
|
|
|
|
|
|
After the module is added to the project, you need to define a couple of Public variables and create the procedure that sets up the program. The public variables are used to provide your entire program with access to the database object. Once you define the variables, you need to create a Sub Main procedure to set up the database information and display the MDI parent form. The Public variable declarations and the Sub Main procedure are shown in Listing 17.4. |
|
|
|
|
|
|
|
|
Listing 17.4 MDIPROCS.TXTUse Sub Main to Set Up the Database and Load the Main Form |
|
|
|
|
|
|
|
|
Public CustDb As Database, CustRset As Recordset
Public CreateForm As Boolean
Sub Main()
Set CustDb = DBEngine.Workspaces(0).OpenDatabase("D:\VB6Book\NewDb.mdb")
Set CustRset = CustDb.OpenRecordset("Customers", dbOpenDynaset)
mdiMain.Show
CreateForm = True
End Sub |
|
|
|
|
|
|
|
|
After you create the Sub Main procedure, you need to change the project options to make Sub Main the startup object of the program. |
|
|
|
|
|
|
|
|
The next two procedures are the ones which either display information about a current customer or set up the information form for you to enter a new customer. These procedures are called by the appropriate menu items of the MDI form. The key feature to note in these procedures is that the ActiveForm property of the MDI form is used to designate which child form will receive the data being sent. The ClearCust and ShowCust procedures are shown in Listing 17.5. |
|
|
|
|
|
|
|
|
Listing 17.5 MDIPROCS2.TXTUse the ActiveForm Property to Send the Output of the Procedure to the Proper Location |
|
|
|
|
|
|
|
|
Public Sub ClearCust()
Dim I As Integer
For I = 0 To 5
mdiMain.ActiveForm.txtMember(I).Text = ""
Next I
End Sub |
|
|
|
|
|